package com.neoz.demo.javabasic;

import java.io.*;

import com.neoz.demo.javabasic.util.CmdUtil;

public class ByteStream {

	public static void main(String[] args) throws IOException {
		ByteArrayOutputStream f = new ByteArrayOutputStream();
		String s = "I'm a string, indeed.";
		byte buf[] = s.getBytes();
		
		CmdUtil.printTitle("print .toString()");
		f.write(buf);
		CmdUtil.print(f.toString());

		CmdUtil.printTitle("print each byte");
		byte b[] = f.toByteArray();
		for (int i = 0; i < b.length; i++) {
			System.out.print((char) b[i]);
		}
		CmdUtil.print("");
		
		CmdUtil.printTitle("print to an OutputStream(d:\\ByteStream.txt)");
		OutputStream f2 = new FileOutputStream("d:\\ByteStream.txt");
		f.writeTo(f2);
		f2.close();
	}

}
